/*
 * Copyright (c) 2023 hpmicro
 * SPDX-License-Identifier: BSD-3-Clause
 *
 */

#include "board.h"
#include "rtt_port.h"
#include "hpm_gpio_drv.h"
#include <stdlib.h>
#include <rtthread.h>

#define THREAD_PRIORITY         25
#define THREAD_STACK_SIZE       4096
#define THREAD_TIMESLICE        1

static rt_thread_t tidled = RT_NULL;

void rt_hw_board_init(void)
{
    board_init();
    rtt_base_init();

    rt_hw_reset();
}

static void led_thread_entry(void *param)
{
  gpio_write_pin(BOARD_APP_LED1_CTRL, BOARD_APP_LED1_INDEX, BOARD_APP_LED1_PIN, 1);
  gpio_write_pin(BOARD_APP_LED2_CTRL, BOARD_APP_LED2_INDEX, BOARD_APP_LED2_PIN, 0);

  for (;;)
  {
    gpio_toggle_pin(BOARD_APP_LED1_CTRL, BOARD_APP_LED1_INDEX, BOARD_APP_LED1_PIN);
    gpio_toggle_pin(BOARD_APP_LED2_CTRL, BOARD_APP_LED2_INDEX, BOARD_APP_LED2_PIN);
    rt_thread_mdelay(1000);
  }
}

int main(void)
{
    tidled = rt_thread_create("led_thread_entry", led_thread_entry, RT_NULL, THREAD_STACK_SIZE, THREAD_PRIORITY, THREAD_TIMESLICE);
    if (tidled != NULL)
    {
      rt_thread_startup(tidled);
      rt_kprintf("Start LED thread ...\n");
    }
    else
    {
      rt_kprintf("Could not create LED thread!\n");
    }

    return 0;
}